package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName SearchController
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/7/8
 * @Version 1.0
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
     * 接收所有条件参数，并封装成一个SearchParam，所有条件都是在请求路径以键值对形式拼接
     * @param searchParam
     * @return
     */
    @GetMapping("/search.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request){
        //查询条件字符串
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult result= mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "search";
    }
}
